package com.demo.service.impl;

import com.demo.dao.UserMapper;
import com.demo.domain.User;
import com.demo.service.UserService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service("userService")
@Transactional
public class UserServiceImpl implements UserService {
    @Autowired
    private UserMapper userMapper;

    @Override
    public boolean save(User user) {
        Integer id = user.getId();
        if (id!=null){ //修改
            int updated=userMapper.update(user);
            System.out.println("updated======>:"+updated);
            if (updated>0){
                return true;
            }
            return false;
        }else {
            int added=userMapper.add(user);
            if (added>0){
                return true;
            }
            return false;
        }
    }

   /* @Override
    public List<User> list() {
        return userMapper.list();
    }*/

    @Override
    public Boolean del(int id) {
      int rows= userMapper.del(id);
      if (rows>0){
          return true;
      }
      return false;
    }

    @Override
    public PageInfo<User> list(int currentPageInt, int pageSizeInt) {
        PageHelper.startPage(currentPageInt, pageSizeInt);
        List<User> list= userMapper.list();
        return new PageInfo<>(list);
    }


}
